package com.yww.controller;


import com.yww.entity.Follow;
import com.yww.entity.FollowParam;
import com.yww.service.IFollowService;
import com.yww.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 雯雯yang
 * @since 2020-06-10
 */
@RestController
@RequestMapping("/follow")
public class FollowController {
    @Autowired
    IFollowService iFollowService;

    @RequestMapping("/insertToFollow")
    public Object insertToFollow(Follow follow){
        boolean save = iFollowService.save(follow);
        if(save){
            return new Result(0,"添加成功");
        }
        return new Result(1,"添加失败");
    }

    /**
     * (查) 多条件分页查询追踪记录
     * @param
     * @return
     */
    @RequestMapping("/getFollowById")
    public Object getFollowById(FollowParam followParam, @RequestParam(required = false,defaultValue = "1")Integer page, @RequestParam(required = false,defaultValue = "10") Integer limit){
        List<FollowParam> followById = iFollowService.getFollowById(followParam);
        followParam.setPage(null);
        followParam.setLimit(null);
        List<FollowParam> followById2 = iFollowService.getFollowById(followParam);
        if(followById!=null){
            return  new Result(0,"成功",followById2.size(),followById);
        }
        return  new Result(1,"失败");

    }


    /**
     * (全查) 追踪记录
     * @param
     * @return
     */
    @RequestMapping("/getFollowList")
    public Object getFollowList(FollowParam followParam, @RequestParam(required = false,defaultValue = "1")Integer page, @RequestParam(required = false,defaultValue = "10") Integer limit){
        List<FollowParam> followById = iFollowService.getFollowList(followParam);
        followParam.setPage(null);
        followParam.setLimit(null);
        List<FollowParam> followById2 = iFollowService.getFollowList(followParam);
        if(followById!=null){
            return  new Result(0,"成功",followById2.size(),followById);
        }
        return  new Result(1,"失败");

    }


}
